<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script>
        window.hdjs = {};
        window.hdjs.base = '../';
        window.hdjs.uploader = 'php/uploader.php?';
        window.hdjs.filesLists = 'php/filesLists.php?';
    </script>
    <script src="../require.js"></script>
    <script src="../config.js"></script>
</head>
<body style="padding: 50px;">
<div class="form-group">
    <textarea id="text" cols="30" rows="10" class="form-control">后盾人 人人做后盾</textarea>
</div>
<button id="bt1" class="btn btn-success btn-sm">插入到尾部</button>
<button id="bt2" class="btn btn-success btn-sm">插入到第二个字</button>
<button id="bt3" class="btn btn-success btn-sm">获取当前位置</button>
<script>
    require(['hdjs','bootstrap'], function (hdjs) {
        $("#bt1").click(function () {
            //插入到文本框尾部
            hdjs.caret('#text', -1)
        });
        $("#bt2").click(function () {
            //插入到指定位置
            hdjs.caret('#text', 2)
        });
        $("#bt3").click(function () {
            //获取位置
            hdjs.caret('#text', function (pos) {
                alert('当前位置'+pos);
            })
        });
    })
</script>
</body>
</html>